package cn.liontalk.ProxyPattern.pattern1;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class LoggerInterceptor implements InvocationHandler {

    private  Object target;

    public LoggerInterceptor(Object target){
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("Entered "+target.getClass().getName()+"-"+method.getName()+",with arguments{"+args[0]+"}");
        //调用对象和方法
        Object result   = method.invoke(target, args);
        System.out.println("Before return:"+result);
        return result ;
    }
}
